<template>
  <div class="approvals-container">
    <div class="app-container">
      <!-- 组织架构 -->
      <el-card>
        <!-- 头部 -->
        <el-row
          type="flex"
          justify="space-between"
          align="middle"
          style="height: 40px"
        >
          <!-- 左边 -->
          <el-col>
            <span>江苏传智播客股份有限公司</span>
          </el-col>
          <!-- / 左边 -->

          <!-- 右边 -->
          <el-col :span="4">
            <el-row type="flex" justify="end">
              <el-col>负责人</el-col>

              <el-col>
                <!-- 下拉菜单 element -->
                <el-dropdown>
                  <span class="el-dropdown-link">
                    操作
                    <i class="el-icon-arrow-down el-icon--right" />
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>添加子部门</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </el-col>
            </el-row>
          </el-col>
          <!-- / 右边 -->
        </el-row>
        <!-- / 头部 -->

        <!-- 树 -->
        <el-tree
          :data="departs"
          node-key="id"
          default-expand-all
          :expand-on-click-node="true"
          :props="defaultProps"
        >
          <span slot-scope="{ node }" class="custom-tree-node">
            <el-col>
              <span>{{ node.label }}</span>
            </el-col>

            <el-col :span="4">
              <el-row type="flex" justify="end">
                <el-col>{{ node.label }}</el-col>

                <el-col class="custom-tree-node">
                  <!-- 下拉菜单 element -->
                  <el-dropdown>
                    <span class="el-dropdown-link">
                      操作
                      <i class="el-icon-arrow-down el-icon--right" />
                    </span>
                    <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item>添加子部门</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
                </el-col>
              </el-row>
            </el-col>
          </span>
        </el-tree>

        <!-- / 树 -->
      </el-card>
    </div>
  </div>
</template>

<script>
// import { getDepartment } from '@/api/departments'
export default {
  data() {
    return {
      departs: [
        { name: '总裁办', children: [{ name: '董事会' }] },
        { name: '行政部' },
        { name: '人事部' }
      ],
      defaultProps: {
        children: 'children',
        label: 'name'
      }
    }
  },
  created() {
    this.getDepartmentlist()
  },
  methods: {
    handleNodeClick(data) {
      console.log(data)
    },
    async getDepartmentlist() {
      // const res = await getDepartment()
      // this.data = res.depts
    }
  }
}
</script>

<style>
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
</style>
